package com.starlight.ts_clouddev.util;

import lombok.Data;

import java.time.LocalDateTime;

/**
 * @Author yfy2001
 * @date 2023/4/4 13:22
 */
@Data
public class CloudResponse<T> {
    /**
     * 时间
     */
    private LocalDateTime time;
    /**
     * 状态码
     */
    private Status status;
    /**
     * 信息
     */
    private String message;
    /**
     * 数据
     */
    private T data;

    /**
     * 成功返回
     * @param data
     * @return
     * @param <T>
     */
    public static <T> CloudResponse<T> success(T data){
        CloudResponse<T> cloudResponse =new CloudResponse<>();
        cloudResponse.setTime(LocalDateTime.now());
        cloudResponse.setStatus(Status.OK);
        cloudResponse.setMessage("操作成功！");
        cloudResponse.setData(data);
        return cloudResponse;
    }

    /**
     * 失败返回
     * @param data
     * @return
     * @param <T>
     */
    public static <T> CloudResponse<T> fail(T data){
        CloudResponse<T> cloudResponse =new CloudResponse<>();
        cloudResponse.setTime(LocalDateTime.now());
        cloudResponse.setStatus(Status.ERROR);
        cloudResponse.setMessage("操作失败：");
        cloudResponse.setData(data);
        return cloudResponse;
    }
}
